package com.fuhaiwei.domain.dao.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.hibernate.Transaction;

import com.fuhaiwei.domain.dao.UserDao;
import com.fuhaiwei.domain.model.User;

public abstract class UserDaoMock implements UserDao {

	private int count = 5;
	private Map<String, List> userDBMock;

	public void delete(int id) {
		// TODO
	}

	public void delete(User user) {
		// TODO
	}

	public List findAll() {
		return null;
	}

	public List findByUsername(String username) {
		if (userDBMock.containsKey(username)) {
			return userDBMock.get(username);
		} else {
			return new ArrayList();
		}
	}

	public User get(int id) {
		return null;
	}

	public void save(User user) {
		user.setId(count++);
		userDBMock.put(user.getUsername(), Arrays.asList(new User[] { user }));
	}

	public void update(User user) {
		// TODO
	}

	public Transaction beginTransaction() {
		return new TransactionMock();
	}

	public void closeSession() {
		// TODO
	}

	public void reset() {
		userDBMock = createUserDBMock();
	}

	public abstract Map<String, List> createUserDBMock();

	public Map<String, List> getUserDBMock() {
		return userDBMock;
	}

	public void setUserDBMock(Map<String, List> userDBMock) {
		this.userDBMock = userDBMock;
	}

}